package com.itheima.goods.controller;

import com.itheima.goods.pojo.Brand;
import com.itheima.goods.service.BrandService;
import entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    /**
     * 查询所有的品牌信息
     * @return
     */
    @GetMapping("/All")
    public Result findAllBrand(){
        return this.brandService.findAllBrand();
    }

    /**
     * 添加品牌信息
     * @param brand
     * @return
     */
    @PostMapping("/add")
    public Result addBrand(@RequestBody Brand brand){
        return this.brandService.addBrand(brand);
    }

    /**
     * 分页查询品牌信息
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/search/{page}/{size}")
    public Result findBrandByPage(@PathVariable("page") Integer page, @PathVariable("size") Integer size){
        return this.brandService.findBrandByPage(page,size);
    }

    /**
     * 根据id查询品牌的信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") Integer id){
        return this.brandService.findById(id);
    }

    /**
     * //更新（修改品牌信息）
     * @param id
     * @param brand
     * @return
     */
    @PutMapping("/{id}")
    public Result updateBrandById(@PathVariable("id") Integer id, @RequestBody Brand brand ){
        return this.brandService.updateBrandById(id,brand);
    }
    //删除（删除品牌信息）
    @DeleteMapping("/{id}")
    public Result deleteBrandById(@PathVariable("id") Integer id){
        return this.brandService.deleteBrandById(id);
    }



}
